<%-- 
    Document   : index
    Created on : 14-mar-2012, 15:49:45
    Author     : Edu
--%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.ResultSet"%>


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%  
        HttpSession sesion = request.getSession();
        Connection conn=null; 
        String bbddString = new String("jdbc:derby://localhost:1527/tienda_edomingo;create=true");

    try{
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    }catch(ClassNotFoundException ex){
        System.out.println("Error al cargar el driver");
        System.out.println(ex.getMessage());
    }

    try{
        conn = DriverManager.getConnection(bbddString);
    }catch (SQLException sqlEx){
        System.out.println("Error al establecer la conexión ");
        System.out.println(sqlEx.getMessage());
    }
        System.out.println("Iniciando ServletOpinion (versión BD)..");
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery ("select * from producto");
         %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    
        <form name="login" method="post" action="LoginServlet">
            <input type="text" name="pass"/>
            <input type="submit">
        </form>
        &nbsp;&nbsp;&nbsp;
        <form name="sel_categoria" method="post" action="FiltroServlet">
            <SELECT NAME="categoria">
                <option selected value="null">--- CATEGORIAS ---
                <option value="Alimentacion" >Alimentacion
                <option value="Drogueria">Drogueria
                <option value="Prensa">Prensa
                <option value="Herramientas">Herramientas
            </SELECT>
            <input type="submit" value="Ir">
        </form>
        <br>
    <center><table border="1">
            
                <%
                int cont=0;
                while (rs.next()){ 
                    if((cont%4)==0){%>
                    <tr>
                    <% }  %>                                
                
                <td><%=rs.getString(2)%><br>
                <%=rs.getString(3)%><br>
                <%=rs.getString(4)%><br>
                <%=rs.getString(5)%><br>
                <input type="button" name="add" value="Añadir a carrito"/></td> 
                 <%if((cont%4)==3){%>
                    </tr>
                <% } %>
                <% cont++; %>
                <% } %>
        </table>
    </center>
    <% out.flush();
    conn.close();%>
    </body>
</html>
